import axios from "axios";
import _ from 'lodash'

// 定义一个接口，规范状态属性有哪些以及属性类型
interface IState {
    collapsed: boolean;
    routeList: Array<any>;
    roleList: Array<any>;
    usersList: Array<any>;
    regionList: Array<any>;
    currentUserList: Array<any>;
    rightList: Array<any>;
    childrenList: Array<any>;
    categoriesList: Array<any>;
    editorText: any;
    newsList: Array<any>;
    currentUserNewsList: Array<any>;
    currentNewsData: {[propsName:string]:any};

}
interface IAction {
    type: string,
    payload: {
        isCollapsed: boolean,
        routeList: Array<any>,
        roleList: Array<any>,
        usersList: Array<any>;
        regionList: Array<any>;
        currentUserList: Array<any>;
        rightList: Array<any>;
        categoriesList: Array<any>;
        childrenList: Array<any>;
        editorText: any;
        newsList: Array<any>;
        currentUserNewsList: Array<any>;
        currentNewsData: {[propsName:string]:any};
    }
}
export default {
    namespace: 'StandBox',
    state: {
        // 侧边栏是否收缩
        collapsed: false,
        routeList: [],
        roleList: [],
        usersList: [],
        regionList: [],
        currentUserList: [],
        rightList: [],
        childrenList: [],
        categoriesList: [],
        editorText: '',
        newsList: [],
        currentUserNewsList: [],
        currentNewsData: null
    },
    // 异步任务
    effects: {
        // 形参action存放dispatch传递过来的对象信息，形参obj存放封装redux-saga的接口（call() 用于异步获取数据,put()用于传递数据给reducer）
        //#region 路由配置信息
        // 获取路由配置信息 生成器函数 
        *getRouteList(action: any, obj: any): any {
            // console.log(action, obj);
            let res = yield obj.call(getRouteListRequest);
            res = adjustLimits(res);
            // console.log(res);
            yield obj.put({
                type: 'getRouteConfigList',
                payload: {
                    routeList: res
                }
            })
        },
        *getRightList(action: any, obj: any): any {
            let res = yield obj.call(getRightListRequest);
            // console.log(res);
            yield obj.put({
                type: 'getRightConfigList',
                payload: {
                    rightList: res
                }
            })
            localStorage.setItem('rightList',JSON.stringify(res));
        },
        *getChildrenList(action: any, obj: any): any {
            let res = yield obj.call(getChildrenListRequest);
            // console.log(res);
            yield obj.put({
                type: 'getChildrenConfigList',
                payload: {
                    childrenList: res
                }
            })
            localStorage.setItem('childrenList',JSON.stringify(res));
        },
        
        // 删除对应路由配置信息 生成器函数 
        *deleteRouteList(action: any, obj: any): any {
            const { payload: {
                routeItem, setLoading, routes, setDeleteOpen, setDelConfirmLoading
            } } = action;
            yield obj.call(deleteRouteListRequest, routeItem);
            // 这里还可以调用yield obj.call(getRouteListRequest);重新发起网络请求获取数据，但是减少网络请求可以优化性能
            //获取删除对应路由后的路由配置信息（非网络请求方式）
            const res = deleteLimits(routes, routeItem);
            yield obj.put({
                type: 'getRouteConfigList',
                payload: {
                    routeList: res
                }
            })
            // 关闭表格的loading
            setLoading && setLoading(false);
            // 关闭对话框的异步操作loading
            setDelConfirmLoading && setDelConfirmLoading(false);
            // 关闭对话框
            setDeleteOpen && setDeleteOpen(false);
        },

        // 修改路由配置信息 生成器函数 
        *modifyRouteList(action: any, obj: any): any {
            const { payload: {
                routeItem, routes
            } } = action;
            yield obj.call(modifyRouteListRequest, routeItem);
            // console.log(res);
            const res = modifyLimits(routes, routeItem);
            yield obj.put({
                type: 'getRouteConfigList',
                payload: {
                    routeList: res
                }
            })
        },
        //#endregion

        //#region 权限配置信息
        // 获取角色配置信息 生成器函数 
        *getRoleList(action: any, obj: any): any {
            const { payload: {
                setLoading
            } } = action;
            const res = yield obj.call(getRoleListRequest);
            yield obj.put({
                type: 'getRoleConfigList',
                payload: {
                    roleList: res
                }
            })
            setLoading && setLoading(false);
        },

        // 删除对应角色配置信息 生成器函数 
        *deleteRoleList(action: any, obj: any): any {
            const { payload: {
                roleItem, setLoading, roles, setDeleteOpen, setDelConfirmLoading
            } } = action;
            yield obj.call(deleteRoleListRequest, roleItem);
            // 这里还可以调用yield obj.call(getRouteListRequest);重新发起网络请求获取数据，但是减少网络请求可以优化性能
            //获取删除对应路由后的路由配置信息（非网络请求方式）
            const res = deleteLocalRole(roles, roleItem);
            yield obj.put({
                type: 'getRoleConfigList',
                payload: {
                    roleList: res
                }
            })
            // 关闭表格的loading
            setLoading && setLoading(false);
            // 关闭对话框的异步操作loading
            setDelConfirmLoading && setDelConfirmLoading(false);
            // 关闭对话框
            setDeleteOpen && setDeleteOpen(false);
        },

        // 修改路由配置信息 生成器函数 
        *modifyRoleList(action: any, obj: any): any {
            const { payload: {
                roleItem, roles, setLoading,
                setModifyConfirmLoading,
                setModifyRoleOpen
            } } = action;
            yield obj.call(modifyRoleListRequest, roleItem);
            // console.log(res);
            const res = modifyRole(roles, roleItem);
            yield obj.put({
                type: 'getRoleConfigList',
                payload: {
                    roleList: res
                }
            })
            setModifyConfirmLoading && setModifyConfirmLoading(false);
            setModifyRoleOpen && setModifyRoleOpen(false);
            setLoading && setLoading(false);
        },
        //#endregion

        //#region 查用户列表信息
        // 获取用户配置信息 生成器函数 
        *getUsersList(action: any, obj: any): any {
            const { payload: {
                setTableLoading
            } } = action;
            const res = yield obj.call(getUsersListRequest);
            // console.log(res);
            yield obj.put({
                type: 'getUsersConfigList',
                payload: {
                    usersList: res
                }
            })
            setTableLoading && setTableLoading(false);
        },
        // 修改用户配置信息 生成器函数 
        *modifyUsersList(action: any, obj: any): any {
            const { payload: {
                usersItem, users, setLoading, setModifyConfirmLoading, setModifyRoleOpen
            } } = action;
            yield obj.call(modifyUsersListRequest, usersItem);
            // console.log(res);
            const res = modifyUsers(users, usersItem);
            yield obj.put({
                type: 'getUsersConfigList',
                payload: {
                    usersList: res
                }
            })
            setModifyConfirmLoading && setModifyConfirmLoading(false);
            setModifyRoleOpen && setModifyRoleOpen(false);
            setLoading && setLoading(false);
        },
        // 修改用户配置信息 生成器函数 
        *updateUsersList(action: any, obj: any): any {
            const { payload: {
                usersItem, users, setLoading, setUpdateConfirmLoading, setUpdateOpen
            } } = action;
            yield obj.call(updateUsersListRequest, usersItem);
            // console.log(res);
            const res = yield obj.call(getUsersListRequest);
            yield obj.put({
                type: 'getUsersConfigList',
                payload: {
                    usersList: res
                }
            })
            setUpdateConfirmLoading && setUpdateConfirmLoading(false);
            setUpdateOpen && setUpdateOpen(false);
            setLoading && setLoading(false);
        },
        // 删除用户配置信息 生成器函数 
        *deleteUsersList(action: any, obj: any): any {
            const { payload: {
                usersItem, setLoading, users, setDeleteOpen, setDelConfirmLoading
            } } = action;
            yield obj.call(deleteUsersListRequest, usersItem);
            // 这里还可以调用yield obj.call(getRouteListRequest);重新发起网络请求获取数据，但是减少网络请求可以优化性能
            //获取删除对应路由后的路由配置信息（非网络请求方式）
            const res = deleteLocalUsers(users, usersItem);
            yield obj.put({
                type: 'getUsersConfigList',
                payload: {
                    usersList: res
                }
            })
            // 关闭表格的loading
            setLoading && setLoading(false);
            // 关闭对话框的异步操作loading
            setDelConfirmLoading && setDelConfirmLoading(false);
            // 关闭对话框
            setDeleteOpen && setDeleteOpen(false);
        },
        // 新增用户配置信息 生成器函数 
        *addUsersList(action: any, obj: any): any {
            const { payload: {
                usersItem, users, setLoading, setAddConfirmLoading, setAddRoleOpen, resetFields
            } } = action;
            yield obj.call(addUsersListRequest, usersItem);
            // console.log(res);
            const res = yield obj.call(getUsersListRequest);
            yield obj.put({
                type: 'getUsersConfigList',
                payload: {
                    usersList: res
                }
            })
            setAddConfirmLoading && setAddConfirmLoading(false);
            setAddRoleOpen && setAddRoleOpen(false);
            setLoading && setLoading(false);
            // 清空数据
            resetFields && resetFields();
        },
        //#endregion

        //#region 查区域信息
        *getRegionList(action: any, obj: any): any {
            const { payload: {
                setLoading
            } } = action;
            const res = yield obj.call(getRegionListRequest);
            // console.log(res);
            yield obj.put({
                type: 'getRegionConfigList',
                payload: {
                    regionList: res
                }
            })
            setLoading && setLoading(false);
        },
        //#endregion

        //#region 获取当前角色信息
        *getCurrentUserData(action: any, obj: any): any {
            const { payload: {
                currentItem, message, navigate
            } } = action;
            const res = yield obj.call(getCurrentUserRequest, currentItem);
            // console.log(res);
            if ((res as Array<any>).length > 0) {
                yield obj.put({
                    type: 'getCurrentUserList',
                    payload: {
                        currentUserList: res
                    }
                })
                localStorage.setItem('token', JSON.stringify(res));
                message && message.success(`登录成功!`);
                navigate && navigate('/home');
            }
            else {
                message.error(`登录失败，请检查用户名、密码以及权限!`);
            }
        },
        //#endregion

        //#region 获取新闻分类信息
        *getCategoriesList(action: any, obj: any): any {
            // const { payload: {
            //     setLoading
            // } } = action;
            const res = yield obj.call(getCategoriesListRequest);
            // console.log(res);
            yield obj.put({
                type: 'getCategoriesConfigList',
                payload: {
                    categoriesList: res
                }
            })
            // setLoading && setLoading(false);
        },
        //#endregion

        //#region 新闻信息
        // 查询新闻
        *getNewsList(action: any, obj: any): any {
            // console.log(action, obj);
            let res = yield obj.call(getNewsListRequest);
            // console.log(res);
            yield obj.put({
                type: 'getNewsConfigList',
                payload: {
                    newsList: res
                }
            })
        },
        *getCurrentUserNewsList(action: any, obj: any): any {
            const { payload: {
                currentUser,auditState,setLoading
            } } = action;
            let res = yield obj.call(getCurrentUserNewsListRequest,currentUser,auditState);
            // console.log(res);
            yield obj.put({
                type: 'getCurrentUserNewsConfigList',
                payload: {
                    currentUserNewsList: res
                }
            })
            setLoading&&setLoading(false);
        },
        // 添加新闻
        *addNewsList(action: any, obj: any): any {
            const { payload: {
                newsItem,auditState,navigate
            } } = action;
            yield obj.call(addNewsListRequest, newsItem);
            // console.log(res);
            const res = yield obj.call(getNewsListRequest);
            yield obj.put({
                type: 'getNewsConfigList',
                payload: {
                    newsList: res
                }
            })
            auditState===0?navigate('/news-manage/draft'):navigate('/audit-manage/list');
        },

        // 删除新闻
        *deleteNewsList(action: any, obj: any): any {
            const { payload: {
                newsItem, setLoading, setDeleteOpen, setDelConfirmLoading,auditState,currentUser
            } } = action;
            yield obj.call(deleteNewsListRequest, newsItem);
            const res = yield obj.call(getCurrentUserNewsListRequest,currentUser,auditState);
            yield obj.put({
                type: 'getCurrentUserNewsConfigList',
                payload: {
                    currentUserNewsList: res
                }
            })
            const res2 = yield obj.call(getNewsListRequest);
            yield obj.put({
                type: 'getNewsConfigList',
                payload: {
                    newsList: res2
                }
            })
            // 关闭表格的loading
            setLoading && setLoading(false);
            // 关闭对话框的异步操作loading
            setDelConfirmLoading && setDelConfirmLoading(false);
            // 关闭对话框
            setDeleteOpen && setDeleteOpen(false);
        },

        // 获取当前id的新闻信息详细信息
        *getCurrentNewsDetail(action: any, obj: any): any {
            const { payload: {
                id,navigate,patchName
            } } = action;
            console.log(navigate,patchName)
            let res = yield obj.call(getCurrentNewsDetailRequest,id);
            // console.log(res);
            yield obj.put({
                type: 'getCurrentNewsDetailList',
                payload: {
                    currentNewsData: res
                }
            })
            navigate&&patchName&&navigate(patchName);
        },
        //#endregion
    },

    //reducers里面属性方法不能与effect里面的函数名一样
    reducers:
    {
        // 伸缩侧边栏
        flexSider(prevState: IState, action: IAction) {
            // console.log('action',action)
            const newState = _.cloneDeep(prevState);
            newState.collapsed = _.cloneDeep(action.payload.isCollapsed);
            return newState
        },

        //获取路由配置信息
        getRouteConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.routeList = _.cloneDeep(action.payload.routeList);
            return newState
        },

        //获取角色配置信息
        getRoleConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.roleList = _.cloneDeep(action.payload.roleList);
            return newState
        },

        //获取用户配置信息
        getUsersConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.usersList = _.cloneDeep(action.payload.usersList);
            return newState
        },

        //获取区域信息
        getRegionConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.regionList = _.cloneDeep(action.payload.regionList);
            return newState
        },

        //获取当前用户信息
        getCurrentUserList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.currentUserList = _.cloneDeep(action.payload.currentUserList);
            return newState
        },

        //获取权限信息
        getRightConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.rightList = _.cloneDeep(action.payload.rightList);
            return newState
        },
        //获取子权限信息
        getChildrenConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.childrenList = _.cloneDeep(action.payload.childrenList);
            return newState
        },
        //获取新闻分类信息
        getCategoriesConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.categoriesList = _.cloneDeep(action.payload.categoriesList);
            return newState
        },

        // 存储富文本编辑器的文本内容信息
        saveEditorText(prevState: any, action: any) {
            const { payload: {
                editorText
            } } = action;
            const newState = _.cloneDeep(prevState);
            newState.editorText = _.cloneDeep(editorText);
            return newState
        },

        //获取新闻信息
        getNewsConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.newsList = _.cloneDeep(action.payload.newsList);
            return newState
        },
        //获取当前用户新闻信息
        getCurrentUserNewsConfigList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.currentUserNewsList = _.cloneDeep(action.payload.currentUserNewsList);
            return newState
        },

        //获取新闻详细信息
        getCurrentNewsDetailList(prevState: any, action: any) {
            const newState = _.cloneDeep(prevState);
            newState.currentNewsData = _.cloneDeep(action.payload.currentNewsData);
            return newState
        },
    },
}
//#region 路由配置信息
// 发起网络请求，获取路由列表信息
const getRouteListRequest = async () => {
    let RoutesPromise = null;
    await axios.get(`http://localhost:3000/rights?_embed=children`).then(res =>
        RoutesPromise = res.data
    ).catch(error => console.log(error));
    return RoutesPromise
}
const getRightListRequest = async () => {
    let RoutesPromise = null;
    await axios.get(`http://localhost:3000/rights`).then(res =>
        RoutesPromise = res.data
    ).catch(error => console.log(error));
    return RoutesPromise
}
const getChildrenListRequest = async () => {
    let RoutesPromise = null;
    await axios.get(`http://localhost:3000/children`).then(res =>
        RoutesPromise = res.data
    ).catch(error => console.log(error));
    return RoutesPromise
}
// 发起网络请求，删除对应路由列表信息
const deleteRouteListRequest = async (item: any) => {
    let RoutesPromise = null;
    if (item.grade === 1) {
        await axios.delete(`http://localhost:3000/rights/${item.id}`).then(res =>
            RoutesPromise = res.data
        ).catch(error => console.log(error));
    }
    else {
        await axios.delete(`http://localhost:3000/children/${item.id}`).then(res =>
            RoutesPromise = res.data
        ).catch(error => console.log(error));
    }

    return RoutesPromise
}

// 发起网络请求，修改路由列表信息
const modifyRouteListRequest = async (item: any) => {
    let RoutesPromise = null;
    console.log(item);
    const newItem = _.cloneDeep(item);
    if (item.grade === 1) {
        await axios.patch(`http://localhost:3000/rights/${item.id}`, {
            ...newItem
        }).then(res =>
            RoutesPromise = res.data
        ).catch(error => console.log(error));
    }
    else {
        await axios.patch(`http://localhost:3000/children/${item.id}`, {
            ...newItem
        }).then(res =>
            RoutesPromise = res.data
        ).catch(error => console.log(error));
    }
    return RoutesPromise
}

//调整路由配置信息，增加title属性，该属性的值=label 递归函数
const adjustLimits = (dataSource: Array<any>) => {
    return _.cloneDeep(dataSource).map((item: any) => {
        if (item.children?.length > 0) {
            item.children = adjustLimits(item.children)
        }
        item.title = item.label
        return item
    })
}

//删除对应的路由配置信息，递归函数
const deleteLimits = (dataSource: Array<any>, dataItem: { id: number, rightId: number, grade: number }) => {
    const { id } = dataItem;
    return _.cloneDeep(dataSource).filter((item: any) => {
        if (item.children?.length > 0) {
            item.children = deleteLimits(item.children, dataItem)
        }
        return item.id !== id
    })
}

//找出对应的路由配置信息，递归函数
const modifyLimits = (dataSource: Array<any>, dataItem: { id: number, rightId: number, grade: number }) => {
    const { id } = dataItem;
    return _.cloneDeep(dataSource).map((item: any) => {
        if (item.id === id) {
            item = _.cloneDeep(dataItem);
        }
        else {
            if (item.children?.length > 0) {
                item.children = modifyLimits(item.children, dataItem)
            }
        }
        return item
    })
}
//#endregion

//#region 角色列表
// 发起网络请求，获取角色列表信息
const getRoleListRequest = async () => {
    let rolePromise = null;
    await axios.get(`http://localhost:3000/roles`).then(res =>
        rolePromise = res.data
    ).catch(error => console.log(error));
    return rolePromise
}

// 发起网络请求，删除对应角色列表信息
const deleteRoleListRequest = async (item: any) => {
    let rolePromise = null;
    await axios.delete(`http://localhost:3000/roles/${item.id}`).then(res =>
        rolePromise = res.data
    ).catch(error => console.log(error));
    return rolePromise
}

// 发起网络请求，修改对应角色列表信息
const modifyRoleListRequest = async (item: any) => {
    let rolePromise = null;
    await axios.patch(`http://localhost:3000/roles/${item.id}`, {
        ...item
    }).then(res =>
        rolePromise = res.data
    ).catch(error => console.log(error));
    return rolePromise
}
//删除对应的角色列表信息，递归函数
const deleteLocalRole = (dataSource: Array<any>, dataItem: { id: number }) => {
    const { id } = dataItem;
    return _.cloneDeep(dataSource).filter((item: any) => {
        if (item.children?.length > 0) {
            item.children = deleteLocalRole(item.children, dataItem)
        }
        return item.id !== id
    })
}

//找出对应的角色列表信息，递归函数
const modifyRole = (dataSource: Array<any>, dataItem: { id: number }) => {
    const { id } = dataItem;
    return _.cloneDeep(dataSource).map((item: any) => {
        if (item.id === id) {
            item = _.cloneDeep(dataItem);
        }
        else {
            if (item.children?.length > 0) {
                item.children = modifyRole(item.children, dataItem)
            }
        }
        return item
    })
}
//#endregion

//#region 用户列表
// 发起网络请求，获取用户列表信息
const getUsersListRequest = async () => {
    let userPromise = null;
    await axios.get(`http://localhost:3000/users?_expand=role`).then(res =>
        userPromise = res.data
    ).catch(error => console.log(error));
    return userPromise
}
//发起网络请求，修改用户列表信息
const modifyUsersListRequest = async (item: any) => {
    let userPromise = null;
    await axios.patch(`http://localhost:3000/users/${item.id}`, {
        roleState: item.roleState
    }).then(res =>
        userPromise = res.data
    ).catch(error => console.log(error));
    return userPromise
}
//发起网络请求，修改用户列表信息
const updateUsersListRequest = async (item: any) => {
    let userPromise = null;
    await axios.patch(`http://localhost:3000/users/${item.id}`, {
        ...item
    }).then(res =>
        userPromise = res.data
    ).catch(error => console.log(error));
    return userPromise
}
// 发起网络请求，删除对应角色列表信息
const deleteUsersListRequest = async (item: any) => {
    let userPromise = null;
    await axios.delete(`http://localhost:3000/users/${item.id}`).then(res =>
        userPromise = res.data
    ).catch(error => console.log(error));
    return userPromise
}
//发起网络请求，增加用户列表信息
const addUsersListRequest = async (item: any) => {
    let userPromise = null;
    await axios.post(`http://localhost:3000/users`, {
        ...item
    }).then(res =>
        userPromise = res.data
    ).catch(error => console.log(error));
    return userPromise
}
//找出对应的用户列表信息，递归函数
const modifyUsers = (dataSource: Array<any>, dataItem: { id: number }) => {
    const { id } = dataItem;
    return _.cloneDeep(dataSource).map((item: any) => {
        if (item.id === id) {
            item = _.cloneDeep(dataItem);
        }
        else {
            if (item.children?.length > 0) {
                item.children = modifyUsers(item.children, dataItem)
            }
        }
        return item
    })
}

//删除对应的用户列表信息，递归函数
const deleteLocalUsers = (dataSource: Array<any>, dataItem: { id: number }) => {
    const { id } = dataItem;
    return _.cloneDeep(dataSource).filter((item: any) => {
        if (item.children?.length > 0) {
            item.children = deleteLocalUsers(item.children, dataItem)
        }
        return item.id !== id
    })
}
//#endregion

//#region 区域信息
//发起网络请求，查询区域信息
const getRegionListRequest = async () => {
    let regionPromise = null;
    await axios.get(`http://localhost:3000/regions`).then(res =>
        regionPromise = res.data
    ).catch(error => console.log(error));
    return regionPromise
}
//#endregion

//#region 当前用户信息
const getCurrentUserRequest = async (currentItem: any) => {
    let currentUserPromise = null;
    await axios.get(`http://localhost:3000/users?username=${currentItem.username}&password=${currentItem.password}&roleState=true&_expand=role`).then(res =>
        currentUserPromise = res.data
    ).catch(error => console.log(error));
    return currentUserPromise
}
//#endregion

//#region 获取新闻分类信息
const getCategoriesListRequest = async () => {
    let categoriesPromise = null;
    await axios.get(`http://localhost:3000/categories`).then(res =>
        categoriesPromise = res.data
    ).catch(error => console.log(error));
    return categoriesPromise
}
//#endregion

//#region 新闻信息
// 网络请求，查询新闻信息
const getNewsListRequest = async () => {
    let newsPromise = null;
    await axios.get(`http://localhost:3000/news`).then(res =>
        newsPromise = res.data
    ).catch(error => console.log(error));
    return newsPromise
}
const getCurrentUserNewsListRequest = async (item:any,auditState:number) => {
    console.log(item);
    let newsPromise = null;
    await axios.get(`http://localhost:3000/news?author=${item[0].username}&auditState=${auditState}&_expand=category`).then(res =>
        newsPromise = res.data
    ).catch(error => console.log(error));
    return newsPromise
}
// 网络请求，添加新闻信息
const addNewsListRequest = async (item: any) => {
    let userPromise = null;
    await axios.post(`http://localhost:3000/news`, {
        ...item
    }).then(res =>
        userPromise = res.data
    ).catch(error => console.log(error));
    return userPromise
}

// 网络请求，删除新闻信息
const deleteNewsListRequest = async (item: any) => {
    let userPromise = null;
    await axios.delete(`http://localhost:3000/News/${item.id}`).then(res =>
        userPromise = res.data
    ).catch(error => console.log(error));
    return userPromise
}
//网络请求，根据id获取新闻详细信息
const getCurrentNewsDetailRequest = async (id:string) => {
    let currentNewsPromise = null;
    await axios.get(`http://localhost:3000/news/${id}?_expand=category&_expand=role`).then(res =>
    currentNewsPromise = res.data
    ).catch(error => console.log(error));
    return currentNewsPromise
}
//#endregion
export { IState };